package topo.autosearch;

import com.zhtelecom.common.base.MyException;
import com.zhtelecom.common.snmp.SNMPTarget;
import com.zhtelecom.nms.framework.discover.DeviceInfo;
import com.zhtelecom.nms.framework.discover.DiscoverAPI;
import com.zhtelecom.nms.framework.discover.DiscoverConfig;
import com.zhtelecom.nms.framework.discover.ResourceInfo;
import com.zhtelecom.nms.framework.discover.ResourceSearchMothType;
import java.util.List;
import topo.data.NodeDevice;
import topo.data.ResourceType;
import topo.utils.SNMPTargetTool;

public class NodeResourceSearch {
    public List<ResourceInfo> getResourceOfNode(NodeDevice node) throws MyException {
        try {
            initResourceTypeConfig();
            DeviceInfo deviceInfo = new DeviceInfo();
            SNMPTarget snmpTarget = SNMPTargetTool.nodeToSNMPConnInfo(node);
            deviceInfo.setSnmpTarget(snmpTarget);
            return DiscoverAPI.getDiscoverAPI().searchDeviceResource(deviceInfo);
        } catch (Exception ex) {
            throw new MyException(ex);
        }
    }

    private void initResourceTypeConfig() throws MyException {
        try {
            List rsTypeList = ResourceType.getRsTypeList();
            DiscoverConfig.clearAllResourceSearchMoth();
            for (ResourceType rsType : rsTypeList) {
                String className = rsType.getSearchResourceClassName();
                ResourceSearchMothType searchMothType = RsSearchMethodManager.getNewInstanceProcess(className);
                if (searchMothType != null) {
                    searchMothType.setResoureTypeName(rsType.getResoureTypeName());
                    searchMothType.setResouceBaseType(rsType.getResouceBaseTechType());
                    searchMothType.setResourceRSID(rsType.getResourceRSID());
                    searchMothType.setTypeDesc(rsType.getTypeDesc());
                    searchMothType.setDisplayNameCode(rsType.getTypeDesc());
                    searchMothType.setParamCode(rsType.getTypeParam());
                    DiscoverConfig.addResourceType(searchMothType);
                }
            }
        } catch (Exception ex) {
            throw new MyException(ex);
        }
    }
}